<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Docker Swarm 入门 | 小鹏杂谈</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/favicon.ico">
    <meta name="description" content="小鹏杂谈">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/assets/css/0.styles.8516fda1.css" as="style"><link rel="preload" href="/assets/js/app.b9ccfc55.js" as="script"><link rel="preload" href="/assets/js/4.8390fbcb.js" as="script"><link rel="preload" href="/assets/js/1.3334f995.js" as="script"><link rel="preload" href="/assets/js/42.d586cccb.js" as="script"><link rel="prefetch" href="/assets/js/10.8eb4e356.js"><link rel="prefetch" href="/assets/js/11.31befa4c.js"><link rel="prefetch" href="/assets/js/12.da37eb75.js"><link rel="prefetch" href="/assets/js/13.b24ba73c.js"><link rel="prefetch" href="/assets/js/14.3bbed283.js"><link rel="prefetch" href="/assets/js/15.fac60f8d.js"><link rel="prefetch" href="/assets/js/16.b75d2036.js"><link rel="prefetch" href="/assets/js/17.116317c5.js"><link rel="prefetch" href="/assets/js/18.80fdbeda.js"><link rel="prefetch" href="/assets/js/19.459fc46f.js"><link rel="prefetch" href="/assets/js/20.452f30f9.js"><link rel="prefetch" href="/assets/js/21.99f641dc.js"><link rel="prefetch" href="/assets/js/22.081dc33b.js"><link rel="prefetch" href="/assets/js/23.d3455a59.js"><link rel="prefetch" href="/assets/js/24.8f5d39e0.js"><link rel="prefetch" href="/assets/js/25.c3dc47fb.js"><link rel="prefetch" href="/assets/js/26.d93b5cf2.js"><link rel="prefetch" href="/assets/js/27.6d2089a5.js"><link rel="prefetch" href="/assets/js/28.57336847.js"><link rel="prefetch" href="/assets/js/29.903b5e06.js"><link rel="prefetch" href="/assets/js/3.32100170.js"><link rel="prefetch" href="/assets/js/30.274666a3.js"><link rel="prefetch" href="/assets/js/31.fa9bd0f8.js"><link rel="prefetch" href="/assets/js/32.20179720.js"><link rel="prefetch" href="/assets/js/33.2dcc611d.js"><link rel="prefetch" href="/assets/js/34.ba79122c.js"><link rel="prefetch" href="/assets/js/35.bcd9298f.js"><link rel="prefetch" href="/assets/js/36.bf6245d9.js"><link rel="prefetch" href="/assets/js/37.734eb893.js"><link rel="prefetch" href="/assets/js/38.26999070.js"><link rel="prefetch" href="/assets/js/39.cc1f016d.js"><link rel="prefetch" href="/assets/js/40.da84c263.js"><link rel="prefetch" href="/assets/js/41.a96b8efa.js"><link rel="prefetch" href="/assets/js/43.69bb61aa.js"><link rel="prefetch" href="/assets/js/44.3be5a840.js"><link rel="prefetch" href="/assets/js/45.208a3bc3.js"><link rel="prefetch" href="/assets/js/46.2d6cacad.js"><link rel="prefetch" href="/assets/js/47.5add378a.js"><link rel="prefetch" href="/assets/js/48.587139cc.js"><link rel="prefetch" href="/assets/js/49.57f7c25a.js"><link rel="prefetch" href="/assets/js/5.ff1e84d1.js"><link rel="prefetch" href="/assets/js/50.efde6e4a.js"><link rel="prefetch" href="/assets/js/51.c9447e5f.js"><link rel="prefetch" href="/assets/js/52.57a51c35.js"><link rel="prefetch" href="/assets/js/53.4be0f240.js"><link rel="prefetch" href="/assets/js/54.8dabd349.js"><link rel="prefetch" href="/assets/js/55.3b8ae0e4.js"><link rel="prefetch" href="/assets/js/56.07e830b2.js"><link rel="prefetch" href="/assets/js/57.8c0dbdcc.js"><link rel="prefetch" href="/assets/js/58.63387df6.js"><link rel="prefetch" href="/assets/js/59.959bb8c8.js"><link rel="prefetch" href="/assets/js/6.56a2b5cd.js"><link rel="prefetch" href="/assets/js/60.1041d86f.js"><link rel="prefetch" href="/assets/js/61.f58e6c18.js"><link rel="prefetch" href="/assets/js/62.a1a460c7.js"><link rel="prefetch" href="/assets/js/63.6c611c7d.js"><link rel="prefetch" href="/assets/js/64.6711119c.js"><link rel="prefetch" href="/assets/js/65.4655c3b1.js"><link rel="prefetch" href="/assets/js/66.e5dfe864.js"><link rel="prefetch" href="/assets/js/67.37515de0.js"><link rel="prefetch" href="/assets/js/68.0c8ba92d.js"><link rel="prefetch" href="/assets/js/69.52121d38.js"><link rel="prefetch" href="/assets/js/7.6f143d9f.js"><link rel="prefetch" href="/assets/js/70.1ab4d6a1.js"><link rel="prefetch" href="/assets/js/71.dc99dd1d.js"><link rel="prefetch" href="/assets/js/72.02e21e52.js"><link rel="prefetch" href="/assets/js/73.21efc121.js"><link rel="prefetch" href="/assets/js/74.649f4e1d.js"><link rel="prefetch" href="/assets/js/75.331c13e7.js"><link rel="prefetch" href="/assets/js/76.a94b5ff0.js"><link rel="prefetch" href="/assets/js/8.d4d40f2a.js"><link rel="prefetch" href="/assets/js/9.1b8824e7.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8516fda1.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-1156296a><div data-v-1156296a><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-1156296a data-v-1156296a><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-4e82dffc data-v-1156296a data-v-1156296a><h3 class="title" data-v-4e82dffc data-v-4e82dffc>小鹏杂谈</h3> <p class="description" data-v-4e82dffc data-v-4e82dffc>小鹏杂谈</p> <label id="box" class="inputBox" data-v-4e82dffc data-v-4e82dffc><input type="password" value="" data-v-4e82dffc> <span data-v-4e82dffc>Konck! Knock!</span> <button data-v-4e82dffc>OK</button></label> <div class="footer" data-v-4e82dffc data-v-4e82dffc><span data-v-4e82dffc><i class="iconfont reco-theme" data-v-4e82dffc></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-4e82dffc>vuePress-theme-reco</a></span> <span data-v-4e82dffc><i class="iconfont reco-copyright" data-v-4e82dffc></i> <a data-v-4e82dffc><span data-v-4e82dffc>lzpeng723</span>
            
          <span data-v-4e82dffc>2021 - </span>
          2022
        </a></span></div></div> <div class="hide" data-v-1156296a><header class="navbar" data-v-1156296a><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="小鹏杂谈" class="logo"> <span class="site-name">小鹏杂谈</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/运维/" class="nav-link"><i class="undefined"></i>
  运维
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发/" class="nav-link"><i class="undefined"></i>
  开发
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/软件/" class="nav-link"><i class="undefined"></i>
  软件
</a></li><li class="dropdown-item"><!----> <a href="/categories/文档/" class="nav-link"><i class="undefined"></i>
  文档
</a></li><li class="dropdown-item"><!----> <a href="/categories/数据库/" class="nav-link"><i class="undefined"></i>
  数据库
</a></li><li class="dropdown-item"><!----> <a href="/categories/Node.js/" class="nav-link"><i class="undefined"></i>
  Node.js
</a></li><li class="dropdown-item"><!----> <a href="/categories/游戏/" class="nav-link"><i class="undefined"></i>
  游戏
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/minimal-boot/" class="nav-link"><i class="undefined"></i>
  minimal-boot
</a></li><li class="dropdown-item"><!----> <a href="/docs/minimal-cloud/" class="nav-link"><i class="undefined"></i>
  minimal-cloud
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系方式
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://www.zhihu.com/people/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-zhihu"></i>
  知乎
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-1156296a></div> <aside class="sidebar" data-v-1156296a><div class="personal-info-wrapper" data-v-828910c6 data-v-1156296a><img src="/avatar.jpg" alt="author-avatar" class="personal-img" data-v-828910c6> <h3 class="name" data-v-828910c6>
    lzpeng723
  </h3> <div class="num" data-v-828910c6><div data-v-828910c6><h3 data-v-828910c6>66</h3> <h6 data-v-828910c6>Articles</h6></div> <div data-v-828910c6><h3 data-v-828910c6>19</h3> <h6 data-v-828910c6>Tags</h6></div></div> <ul class="social-links" data-v-828910c6></ul> <hr data-v-828910c6></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/运维/" class="nav-link"><i class="undefined"></i>
  运维
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发/" class="nav-link"><i class="undefined"></i>
  开发
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/软件/" class="nav-link"><i class="undefined"></i>
  软件
</a></li><li class="dropdown-item"><!----> <a href="/categories/文档/" class="nav-link"><i class="undefined"></i>
  文档
</a></li><li class="dropdown-item"><!----> <a href="/categories/数据库/" class="nav-link"><i class="undefined"></i>
  数据库
</a></li><li class="dropdown-item"><!----> <a href="/categories/Node.js/" class="nav-link"><i class="undefined"></i>
  Node.js
</a></li><li class="dropdown-item"><!----> <a href="/categories/游戏/" class="nav-link"><i class="undefined"></i>
  游戏
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/minimal-boot/" class="nav-link"><i class="undefined"></i>
  minimal-boot
</a></li><li class="dropdown-item"><!----> <a href="/docs/minimal-cloud/" class="nav-link"><i class="undefined"></i>
  minimal-cloud
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系方式
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://www.zhihu.com/people/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-zhihu"></i>
  知乎
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-4e82dffc data-v-1156296a><h3 class="title" data-v-4e82dffc data-v-4e82dffc>Docker Swarm 入门</h3> <!----> <label id="box" class="inputBox" data-v-4e82dffc data-v-4e82dffc><input type="password" value="" data-v-4e82dffc> <span data-v-4e82dffc>Konck! Knock!</span> <button data-v-4e82dffc>OK</button></label> <div class="footer" data-v-4e82dffc data-v-4e82dffc><span data-v-4e82dffc><i class="iconfont reco-theme" data-v-4e82dffc></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-4e82dffc>vuePress-theme-reco</a></span> <span data-v-4e82dffc><i class="iconfont reco-copyright" data-v-4e82dffc></i> <a data-v-4e82dffc><span data-v-4e82dffc>lzpeng723</span>
            
          <span data-v-4e82dffc>2021 - </span>
          2022
        </a></span></div></div> <div data-v-1156296a><main class="page"><section><div class="page-title"><h1 class="title">Docker Swarm 入门</h1> <div data-v-1ff7123e><i class="iconfont reco-account" data-v-1ff7123e><span data-v-1ff7123e>lzpeng723</span></i> <i class="iconfont reco-date" data-v-1ff7123e><span data-v-1ff7123e>10/3/2021</span></i> <!----> <i class="tags iconfont reco-tag" data-v-1ff7123e><span class="tag-item" data-v-1ff7123e>Docker</span></i></div></div> <div class="theme-reco-content content__default"><h1 id="docker-swarm"><a href="#docker-swarm" class="header-anchor">#</a> Docker Swarm</h1> <p><a href="https://docs.docker.com/engine/swarm/" target="_blank" rel="noopener noreferrer">Docker Swarm<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 和 Docker Compose 一样，都是 Docker 官方容器编排项目，但不同的是，Docker Compose 是一个在单个服务器或主机上创建多个容器的工具，而 Docker Swarm 则可以在多个服务器或主机上创建容器集群服务，对于微服务的部署，显然 Docker Swarm 会更加适合。</p> <p>从 Docker 1.12.0 版本开始，Docker Swarm 已经包含在 Docker 引擎中（<code>docker swarm</code>），并且已经内置了服务发现工具，我们就不需要像之前一样，再配置 Etcd 或者 Consul 来进行服务发现配置了。</p> <div class="custom-block tip"><p class="title"></p><p>注： 若是winows系统，本章节命令必须在管理员下运行</p></div><h2 id="_1-docker-machine-创建-docker-主机"><a href="#_1-docker-machine-创建-docker-主机" class="header-anchor">#</a> 1. Docker Machine 创建 Docker 主机</h2> <p>在进行 Docker Swarm 配置之前，我们还需要说下 Docker 另外一个官方工具 Docker Machine，其作用就是快速帮助我们搭建 Docker 主机环境，比如我们要使用 Docker Swarm，就必须有很多的 Docker 主机来进行操作，Docker Machine 就是最理想的工具。</p> <p>首先进行<a href="/blogs/Docker/docker-machine.html">安装 Docker Machine</a>。</p> <p>我们先使用 Docker Machine 创建四个 Docker 主机，命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker-machine create --driver hyperv --hyperv-virtual-switch=docker manager1 &amp;&amp; \
docker-machine create --driver hyperv --hyperv-virtual-switch=docker manager2 &amp;&amp; \
docker-machine create --driver hyperv --hyperv-virtual-switch=docker worker1 &amp;&amp; \
docker-machine create --driver hyperv --hyperv-virtual-switch=docker worker2
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>执行上面命令，你会发现速度巨慢（如上），原因是从 GitHub 上下载一个<code>boot2docker.iso</code>文件（国内网络没办法），怎么解决呢？很简单，我们使用翻X的浏览器手动下载<code>boot2docker.iso</code>文件，然后拷贝到对应目录下（我电脑的目录<code>C:/Users/ThinkPad/.docker/machine/cache</code>），然后再执行上面的命令，发现速度快的一批。</p> <p>我们可以查看下创建的 Docker 主机信息，命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker-machine ls
NAME       ACTIVE   DRIVER   STATE     URL                       SWARM   DOCKER      ERRORS
manager1   -        hyperv   Running   tcp://192.168.1.10:2376           v19.03.12
manager2   -        hyperv   Running   tcp://192.168.1.11:2376           v19.03.12
worker1    -        hyperv   Running   tcp://192.168.1.12:2376           v19.03.12
worker2    -        hyperv   Running   tcp://192.168.1.13:2376           v19.03.12
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>可以看到，我们创建了四个 Docker 主机（两个 Manager 和两个 Worker），我们还可以连接到任何一台服务器进行操作，命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker-machine ssh manager1
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="可能遇到的问题"><a href="#可能遇到的问题" class="header-anchor">#</a> 可能遇到的问题</h3> <h4 id="卡在-waiting-for-ssh-to-be-available"><a href="#卡在-waiting-for-ssh-to-be-available" class="header-anchor">#</a> 卡在 Waiting for SSH to be available...</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>Running pre-create checks...
(manager1) Unable to get the latest Boot2Docker ISO release version:  Get https://api.github.com/repos/boot2docker/boot2docker/releases/latest: dial tcp: lookup api.github.com: no such host
Creating machine...
(manager1) Unable to get the latest Boot2Docker ISO release version:  Get https://api.github.com/repos/boot2docker/boot2docker/releases/latest: dial tcp: lookup api.github.com: no such host
(manager1) Copying D:\wsl2\docker\vm\cache\boot2docker.iso to D:\wsl2\docker\vm\machines\manager1\boot2docker.iso...
(manager1) Creating SSH key...
(manager1) Creating VM...
(manager1) Using switch &quot;docker&quot;
(manager1) Creating VHD
(manager1) Starting VM...
(manager1) Waiting for host to start...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><p>解决方案见<a href="https://stackoverflow.com/questions/56792664/docker-desktop-windows-10-waiting-for-ssh-to-be-available-certificate-signe" target="_blank" rel="noopener noreferrer">StackOverflow<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>
只需要在创建虚拟机时增加参数<code>--native-ssh</code></p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker-machine --native-ssh create --driver hyperv --hyperv-virtual-switch=docker manager1 &amp;&amp; \
docker-machine --native-ssh create --driver hyperv --hyperv-virtual-switch=docker manager2 &amp;&amp; \
docker-machine --native-ssh create --driver hyperv --hyperv-virtual-switch=docker worker1 &amp;&amp; \
docker-machine --native-ssh create --driver hyperv --hyperv-virtual-switch=docker worker2
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="_2-docker-swarm-配置集群节点"><a href="#_2-docker-swarm-配置集群节点" class="header-anchor">#</a> 2. Docker Swarm 配置集群节点</h2> <p>我们执行下面命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker-machine ssh manager1 &quot;docker swarm init --advertise-addr 192.168.1.10&quot;
Swarm initialized: current node (c6kj4t51l0nzoq3u29pqxiuv6) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-5irhzlufi8nmuj26f61wkuobo46t20uja1igmkbe1rsc9g1c9w-1ucldja96grjps4rxkevrwghb 192.168.1.10:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>上面是在manager1主机上，创建一个 Docker Swarm 管理节点（初始化集群的时候，会自动把当前节点设置为管理节点）。</p> <p>接着，我们在worker1和worker2主机上，创建两个工作节点，并加入到集群中，命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker-machine ssh worker1 &quot;docker swarm join --token SWMTKN-1-5irhzlufi8nmuj26f61wkuobo46t20uja1igmkbe1rsc9g1c9w-1ucldja96grjps4rxkevrwghb 192.168.1.10:2377&quot;
This node joined a swarm as a worker.

$ docker-machine ssh worker2 &quot;docker swarm join --token SWMTKN-1-5irhzlufi8nmuj26f61wkuobo46t20uja1igmkbe1rsc9g1c9w-1ucldja96grjps4rxkevrwghb 192.168.1.10:2377&quot;
This node joined a swarm as a worker.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>还有另外一个manager2主机，需要配置为管理节点，我们需要先在manager1主机上，获取管理节点对应的token，然后再配置为管理节点，命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker-machine ssh manager1 &quot;docker swarm join-token manager&quot;
To add a manager to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-5irhzlufi8nmuj26f61wkuobo46t20uja1igmkbe1rsc9g1c9w-6y84dxjfk3oo38honys4sjmbr 192.168.1.10:2377

$ docker-machine ssh manager2 &quot;docker swarm join --token SWMTKN-1-5irhzlufi8nmuj26f61wkuobo46t20uja1igmkbe1rsc9g1c9w-6y84dxjfk3oo38honys4sjmbr 192.168.1.10:2377&quot;
This node joined a swarm as a manager.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>配置好之后，我们进入manager1主机内（上面的命令也可以在主机内执行），然后查看集群节点的信息，命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker-machine ssh manager1 &quot;docker node ls&quot;
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
c6kj4t51l0nzoq3u29pqxiuv6 *   manager1            Ready               Active              Leader              19.03.12
aynl204ef7bwv8dwmaqfjhh12     manager2            Ready               Active              Reachable           19.03.12
zi0z09j4mm9ny727i8btqfh92     worker1             Ready               Active                                  19.03.12
j44vqncnpt8ztw4z379zgw5a5     worker2             Ready               Active                                  19.03.12
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>Leader表示当然集群的头，Reachable可以理解为头的候选人，头一挂掉它就顶上去了。</p> <p>需要注意的是，我当天配置好之后，把所有的 Docker 主机都stop了，然后隔天重新start之后，出现了下面问题：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker node ls
Error response from daemon: rpc error: code = Unknown desc = The swarm does not have a leader. It's possible that too few managers are online. Make sure more than half of the managers are online.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>好像是集群节点丢失了头，相关问题：<a href="https://q.cnblogs.com/q/96996/" target="_blank" rel="noopener noreferrer">如何处理 docker swarm 集群&quot;The swarm does not have a leader&quot;问题<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，按照文章进行解决：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker swarm init --force-new-cluster
Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (10.0.2.15 on eth0 and 192.168.1.10 on eth1) - specify one with --advertise-addr
$ docker swarm init --force-new-cluster --advertise-addr 192.168.1.10
Error response from daemon: This node is not a swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager.
$ docker node ls
# 卡死
$ docker-machine restart manager1 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>重启不了，一直转圈
没办法，后来我只能删掉四个 Docker 主机，重新进行创建了。</p> <h2 id="_3-docker-service-部署单个集群服务"><a href="#_3-docker-service-部署单个集群服务" class="header-anchor">#</a> 3. Docker Service 部署单个集群服务</h2> <p>上面比较啰嗦，我们接下来正式部署集群服务，拿nginx镜像做为示例，命令（<code>docker service create</code>命令<a href="https://docs.docker.com/engine/reference/commandline/service_create/" target="_blank" rel="noopener noreferrer">详细说明<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>）:</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker service create --replicas 4 -p 8088:80 --name nginx nginx:alpine
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>需要注意的是，<code>--replicas 4</code>表示创建服务的实例个数（默认是一个），啥意思？比如4，就是在四个 Docker 主机上，分别创建一个nginx服务，如果是3，那就是三个 Docker 主机，或者你可以理解为 Docker 主机的个数，另外，REPLICAS会有进度显示，并且执行是异步的。</p> <p>我们也可以手动设置实例个数，命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker service scale nginx=4
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>部署好服务后，我们就可以进行查看了，命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker service ls
ID                  NAME                MODE                REPLICAS            ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
ucymevu7jvds        nginx               replicated          4/4                 nginx:alpine        *:8088-&gt;80/tcp

$ docker service ps nginx
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE           ERROR               PORTS
wikk1lrjvb62        nginx.1             nginx:alpine        manager1            Running             Running 2 minutes ago
54a8tgw3q47y        nginx.2             nginx:alpine        worker1             Running             Running 2 minutes ago
eu4yk2n33zm4        nginx.3             nginx:alpine        worker2             Running             Running 2 minutes ago
8bdu0zwut54q        nginx.4             nginx:alpine        manager2            Running             Running 2 minutes ago
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p>我们任意使用四个 Docker 主机中的一个 IP 地址，浏览器打开：<a href="http://192.168.1.10:8088/" target="_blank" rel="noopener noreferrer">http://192.168.1.10:8088/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>,即可看到nginx服务正在运行</p> <h2 id="_4-集散集群"><a href="#_4-集散集群" class="header-anchor">#</a> 4. 集散集群</h2> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker swarm leave --force
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="_5-docker-stack-部署多个集群服务-以及-gui-管理页面"><a href="#_5-docker-stack-部署多个集群服务-以及-gui-管理页面" class="header-anchor">#</a> 5. Docker Stack 部署多个集群服务，以及 GUI 管理页面</h2> <p>docker service部署的是单个服务，我们可以使用<code>docker stack</code>进行多服务编排部署，使用的同样是<code>docker-compose.yml</code>配置文件，示例：</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">version</span><span class="token punctuation">:</span> <span class="token string">&quot;3&quot;</span>

<span class="token key atrule">services</span><span class="token punctuation">:</span>
  <span class="token key atrule">nginx</span><span class="token punctuation">:</span>
    <span class="token key atrule">image</span><span class="token punctuation">:</span> nginx<span class="token punctuation">:</span>latest
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> 8088<span class="token punctuation">:</span><span class="token number">80</span>
    <span class="token key atrule">deploy</span><span class="token punctuation">:</span>
      <span class="token key atrule">mode</span><span class="token punctuation">:</span> replicated
      <span class="token key atrule">replicas</span><span class="token punctuation">:</span> <span class="token number">4</span>

  <span class="token key atrule">visualizer</span><span class="token punctuation">:</span>
    <span class="token key atrule">image</span><span class="token punctuation">:</span> dockersamples/visualizer<span class="token punctuation">:</span>latest
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> <span class="token string">&quot;8080:8080&quot;</span>
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> <span class="token string">&quot;/var/run/docker.sock:/var/run/docker.sock&quot;</span>
    <span class="token key atrule">deploy</span><span class="token punctuation">:</span>
      <span class="token key atrule">replicas</span><span class="token punctuation">:</span> <span class="token number">1</span>
      <span class="token key atrule">placement</span><span class="token punctuation">:</span>
        <span class="token key atrule">constraints</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>node.role == manager<span class="token punctuation">]</span>

  <span class="token key atrule">portainer</span><span class="token punctuation">:</span>
    <span class="token key atrule">image</span><span class="token punctuation">:</span> portainer/portainer<span class="token punctuation">:</span>latest
    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> <span class="token string">&quot;9000:9000&quot;</span>
    <span class="token key atrule">volumes</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> <span class="token string">&quot;/var/run/docker.sock:/var/run/docker.sock&quot;</span>
    <span class="token key atrule">deploy</span><span class="token punctuation">:</span>
      <span class="token key atrule">replicas</span><span class="token punctuation">:</span> <span class="token number">1</span>
      <span class="token key atrule">placement</span><span class="token punctuation">:</span>
        <span class="token key atrule">constraints</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>node.role == manager<span class="token punctuation">]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br></div></div><p>如上所示，我们总共需要部署三个服务，出了nginx服务作为示例之外，visualizer（<a href="https://github.com/dockersamples/docker-swarm-visualizer" target="_blank" rel="noopener noreferrer">官方地址<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>）和portainer（<a href="https://portainer.io/" target="_blank" rel="noopener noreferrer">官方地址<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>）都是集群 GUI 管理服务。</p> <p>部署命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker stack deploy -c docker-compose.yml deploy-demo
Creating service deploy-demo_nginx
Creating service deploy-demo_visualizer
Creating service deploy-demo_portainer
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>部署成功之后，我们可以查看具体详情，命令：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker stack ls
NAME                SERVICES
deploy-demo         3
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>查看<code>visualizer</code> GUI 集群管理，浏览器打开：<a href="http://192.168.1.10:8080/" target="_blank" rel="noopener noreferrer">http://192.168.1.10:8080/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>
查看<code>portainer</code> GUI 集群管理，需要先配置账号信息，浏览器打开：<a href="http://192.168.1.10:9000/" target="_blank" rel="noopener noreferrer">http://192.168.1.1:9000/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p>可以看到，<code>portainer</code>比<code>visualizer</code>强大太多了，甚至我们所有的操作都可以在<code>portainer</code>上完成。</p> <h2 id="_6-docker-machine、docker-swarm、docker-node、docker-service-和-docker-stack-常用命令"><a href="#_6-docker-machine、docker-swarm、docker-node、docker-service-和-docker-stack-常用命令" class="header-anchor">#</a> 6. docker-machine、docker swarm、docker node、docker service 和 docker stack 常用命令</h2> <h3 id="docker-machine-常用命令"><a href="#docker-machine-常用命令" class="header-anchor">#</a> docker-machine 常用命令</h3> <table><thead><tr><th style="text-align:center;">命令</th> <th style="text-align:center;">说明</th></tr></thead> <tbody><tr><td style="text-align:center;">docker-machine create</td> <td style="text-align:center;">创建一个 Docker 主机（常用<code>-d virtualbox</code>）</td></tr> <tr><td style="text-align:center;">docker-machine ls</td> <td style="text-align:center;">查看所有的 Docker 主机</td></tr> <tr><td style="text-align:center;">docker-machine ssh</td> <td style="text-align:center;">SSH 到主机上执行命令</td></tr> <tr><td style="text-align:center;">docker-machine env</td> <td style="text-align:center;">显示连接到某个主机需要的环境变量</td></tr> <tr><td style="text-align:center;">docker-machine inspect</td> <td style="text-align:center;">输出主机更多信息</td></tr> <tr><td style="text-align:center;">docker-machine kill</td> <td style="text-align:center;">停止某个主机</td></tr> <tr><td style="text-align:center;">docker-machine restart</td> <td style="text-align:center;">重启某台主机</td></tr> <tr><td style="text-align:center;">docker-machine rm</td> <td style="text-align:center;">删除某台主机</td></tr> <tr><td style="text-align:center;">docker-machine scp</td> <td style="text-align:center;">在主机之间复制文件</td></tr> <tr><td style="text-align:center;">docker-machine start</td> <td style="text-align:center;">启动一个主机</td></tr> <tr><td style="text-align:center;">docker-machine status</td> <td style="text-align:center;">查看主机状态</td></tr> <tr><td style="text-align:center;">docker-machine stop</td> <td style="text-align:center;">停止一个主机</td></tr></tbody></table> <h3 id="docker-swarm-常用命令"><a href="#docker-swarm-常用命令" class="header-anchor">#</a> docker swarm 常用命令</h3> <table><thead><tr><th style="text-align:center;">命令</th> <th style="text-align:center;">说明</th></tr></thead> <tbody><tr><td style="text-align:center;">docker swarm init</td> <td style="text-align:center;">初始化集群</td></tr> <tr><td style="text-align:center;">docker swarm join-token worker</td> <td style="text-align:center;">查看工作节点的 token</td></tr> <tr><td style="text-align:center;">docker swarm join-token manager</td> <td style="text-align:center;">查看管理节点的 token</td></tr> <tr><td style="text-align:center;">docker swarm join</td> <td style="text-align:center;">加入集群中</td></tr></tbody></table> <h3 id="docker-node-常用命令"><a href="#docker-node-常用命令" class="header-anchor">#</a> docker node 常用命令</h3> <table><thead><tr><th style="text-align:center;">命令</th> <th style="text-align:center;">说明</th></tr></thead> <tbody><tr><td style="text-align:center;">docker node ls</td> <td style="text-align:center;">查看所有集群节点</td></tr> <tr><td style="text-align:center;">docker node rm</td> <td style="text-align:center;">删除某个节点（<code>-f</code>强制删除）</td></tr> <tr><td style="text-align:center;">docker node inspect</td> <td style="text-align:center;">查看节点详情</td></tr> <tr><td style="text-align:center;">docker node demote</td> <td style="text-align:center;">节点降级，由管理节点降级为工作节点</td></tr> <tr><td style="text-align:center;">docker node promote</td> <td style="text-align:center;">节点升级，由工作节点升级为管理节点</td></tr> <tr><td style="text-align:center;">docker node update</td> <td style="text-align:center;">更新节点</td></tr> <tr><td style="text-align:center;">docker node ps</td> <td style="text-align:center;">查看节点中的 Task 任务</td></tr></tbody></table> <h3 id="docker-service-常用命令"><a href="#docker-service-常用命令" class="header-anchor">#</a> docker service 常用命令</h3> <table><thead><tr><th style="text-align:center;">命令</th> <th style="text-align:center;">说明</th></tr></thead> <tbody><tr><td style="text-align:center;">docker service create</td> <td style="text-align:center;">部署服务</td></tr> <tr><td style="text-align:center;">docker service inspect</td> <td style="text-align:center;">查看服务详情</td></tr> <tr><td style="text-align:center;">docker service logs</td> <td style="text-align:center;">产看某个服务日志</td></tr> <tr><td style="text-align:center;">docker service ls</td> <td style="text-align:center;">查看所有服务详情</td></tr> <tr><td style="text-align:center;">docker service rm</td> <td style="text-align:center;">删除某个服务（<code>-f</code>强制删除）</td></tr> <tr><td style="text-align:center;">docker service scale</td> <td style="text-align:center;">设置某个服务个数</td></tr> <tr><td style="text-align:center;">docker service update</td> <td style="text-align:center;">更新某个服务</td></tr></tbody></table> <h3 id="docker-stack-常用命令"><a href="#docker-stack-常用命令" class="header-anchor">#</a> docker stack 常用命令</h3> <table><thead><tr><th style="text-align:center;">命令</th> <th style="text-align:center;">说明</th></tr></thead> <tbody><tr><td style="text-align:center;">docker stack deploy</td> <td style="text-align:center;">部署新的堆栈或更新现有堆栈</td></tr> <tr><td style="text-align:center;">docker stack ls</td> <td style="text-align:center;">列出现有堆栈</td></tr> <tr><td style="text-align:center;">docker stack ps</td> <td style="text-align:center;">列出堆栈中的任务</td></tr> <tr><td style="text-align:center;">docker stack rm</td> <td style="text-align:center;">删除堆栈</td></tr> <tr><td style="text-align:center;">docker stack services</td> <td style="text-align:center;">列出堆栈中的服务</td></tr> <tr><td style="text-align:center;">docker stack down</td> <td style="text-align:center;">移除某个堆栈（不会删除数据）</td></tr></tbody></table></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">1/28/2022, 8:09:41 AM</span></div></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-70334359><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#_1-docker-machine-创建-docker-主机" class="sidebar-link reco-side-_1-docker-machine-创建-docker-主机" data-v-70334359>1. Docker Machine 创建 Docker 主机</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#可能遇到的问题" class="sidebar-link reco-side-可能遇到的问题" data-v-70334359>可能遇到的问题</a></li><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#_2-docker-swarm-配置集群节点" class="sidebar-link reco-side-_2-docker-swarm-配置集群节点" data-v-70334359>2. Docker Swarm 配置集群节点</a></li><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#_3-docker-service-部署单个集群服务" class="sidebar-link reco-side-_3-docker-service-部署单个集群服务" data-v-70334359>3. Docker Service 部署单个集群服务</a></li><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#_4-集散集群" class="sidebar-link reco-side-_4-集散集群" data-v-70334359>4. 集散集群</a></li><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#_5-docker-stack-部署多个集群服务-以及-gui-管理页面" class="sidebar-link reco-side-_5-docker-stack-部署多个集群服务-以及-gui-管理页面" data-v-70334359>5. Docker Stack 部署多个集群服务，以及 GUI 管理页面</a></li><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#_6-docker-machine、docker-swarm、docker-node、docker-service-和-docker-stack-常用命令" class="sidebar-link reco-side-_6-docker-machine、docker-swarm、docker-node、docker-service-和-docker-stack-常用命令" data-v-70334359>6. docker-machine、docker swarm、docker node、docker service 和 docker stack 常用命令</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#docker-machine-常用命令" class="sidebar-link reco-side-docker-machine-常用命令" data-v-70334359>docker-machine 常用命令</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#docker-swarm-常用命令" class="sidebar-link reco-side-docker-swarm-常用命令" data-v-70334359>docker swarm 常用命令</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#docker-node-常用命令" class="sidebar-link reco-side-docker-node-常用命令" data-v-70334359>docker node 常用命令</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#docker-service-常用命令" class="sidebar-link reco-side-docker-service-常用命令" data-v-70334359>docker service 常用命令</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-swarm.html#docker-stack-常用命令" class="sidebar-link reco-side-docker-stack-常用命令" data-v-70334359>docker stack 常用命令</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div><div class="reco-bgm-panel" data-v-b1d3339e><audio id="bgm" src="/music/1.m4a" data-v-b1d3339e></audio> <div class="reco-float-box" style="bottom:200px;z-index:999999;display:none;" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><img src="https://y.qq.com/music/photo_new/T002R300x300M0000046Etze42qCxC_1.jpg" data-v-b1d3339e></div> <div class="reco-bgm-box" style="left:10px;bottom:10px;z-index:999999;" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><div class="reco-bgm-cover" style="background-image:url(https://y.qq.com/music/photo_new/T002R300x300M0000046Etze42qCxC_1.jpg);" data-v-b1d3339e><div class="mini-operation" style="display:none;" data-v-b1d3339e><i class="reco-bgm reco-bgm-pause" style="display:none;" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-play" style="display:none;" data-v-b1d3339e></i></div> <div class="falut-message" style="display:none;" data-v-b1d3339e>
          播放失败
        </div></div> <div class="reco-bgm-info" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><div class="info-box" data-v-b1d3339e><i class="reco-bgm reco-bgm-music music" data-v-b1d3339e></i>苍穹</div> <div class="info-box" data-v-b1d3339e><i class="reco-bgm reco-bgm-artist" data-v-b1d3339e></i>韩磊</div> <div class="reco-bgm-progress" data-v-b1d3339e><div class="progress-bar" data-v-b1d3339e><div class="bar" data-v-b1d3339e></div></div></div> <div class="reco-bgm-operation" data-v-b1d3339e><i class="reco-bgm reco-bgm-last last" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-pause pause" style="display:none;" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-play play" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-next next" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-volume1 volume" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-mute mute" style="display:none;" data-v-b1d3339e></i> <div class="volume-bar" data-v-b1d3339e><div class="bar" data-v-b1d3339e></div></div></div></div> <div class="reco-bgm-left-box" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><i class="reco-bgm reco-bgm-left" data-v-b1d3339e></i></div></div></div><!----></div></div>
    <script src="/assets/js/app.b9ccfc55.js" defer></script><script src="/assets/js/4.8390fbcb.js" defer></script><script src="/assets/js/1.3334f995.js" defer></script><script src="/assets/js/42.d586cccb.js" defer></script>
  </body>
</html>
